package 面试.遍历算法.String类型题目;

public class 字符倒序输出 {
    public static void main(String[] args) {
        String str = "abc-d-efg";
        char[] chars = str.toCharArray();
        for (int i = 0; i < chars.length/2; i++) {
            //获取头尾的字符
            char c1 = chars[i];
            char c2 = chars[chars.length-1-i];
            //检查头尾字符是否包含"-"
            if ((c1+"").equals("-")  || (c2+"").equals("-")){
                continue;
            }
            //不包含，进行头尾字符交换，实现字符倒序输出
            chars[i] = c2;
            chars[chars.length-1-i] = c1;
        }
        System.out.println(chars);
    }
}
